//
//  GROderListFootView.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/21.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GROderListFootView.h"

@implementation GROderListFootView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)awakeFromNib{
    [super awakeFromNib];
    [self.lookMoreBt.layer setBorderWidth:1];
    [self.lookMoreBt.layer setBorderColor:HEXCOLOR(0xDDDDDD).CGColor];
    [self.statusBtS.layer setBorderWidth:1];
    [self.statusBtS.layer setBorderColor:[HEXCOLOR(0xDDDDDD) CGColor]];
    [self.statusBtT.layer setBorderWidth:1];

}
-(void)setListModel:(GROrderListModel *)listModel {
    _listModel = listModel;
    if (_listModel.lookMore) {
        [self.lookMoreBt setTitle:@"收起来" forState: UIControlStateNormal];
    }else{
        [self.lookMoreBt setTitle: @"查看更多" forState: UIControlStateNormal];
    }
    self.orderPriceLabel.hidden = listModel.byStages;
    self.orderPriceTitleLabel.hidden = listModel.byStages;
    self.rateView.hidden = !listModel.byStages;
    [self.statusBtT.layer setBorderColor:[UIColor clearColor].CGColor];
    self.statusBtT.backgroundColor = HEXCOLOR(0xFBD62D);
    if (listModel.byStages) {
        self.ratePrcieLabel.text = [NSString stringWithFormat:@"%.2lf",self.listModel.firstMoney];
        self.monthPriceLabel.text = [NSString stringWithFormat:@"%.2lf",self.listModel.monthProvide];
        self.stageLabel.text = [NSString stringWithFormat:@"x%ld期",self.listModel.totalStages];
    }else{
        self.orderPriceLabel.text = [NSString stringWithFormat:@"%.2lf",listModel.orderPrice];
    }
    self.lookMoreBt.hidden = listModel.goods.count >2?NO:YES;
    self.lookTopOffset.constant = listModel.goods.count >2 ?25:0;
  //待付款 取消订单 去付款（黄）
  //待发货 联系客服  申请退款(黄)
  //待收货 （申请退货 取消退货（有退货）） 查询物流 确认收货（黄）
  //已完成 申请退货（7天后不允许退货） 评价（黄）
 //已取消 （全部隐藏按钮）
 
    self.statusBtS.hidden = NO;
    self.statusBtT.hidden = NO;
    if (listModel.status == 10) {//已取消
        self.statusBtS.hidden = YES;
        self.statusBtT.hidden = YES;
    }else {//待收货
        if (listModel.status != 5) {
            if (listModel.status == 9) {//已完成
                [self.statusBtS setTitle:@"查询物流" forState:UIControlStateNormal];
                [self.statusBtT setTitle:(listModel.isComment ?@"评价":@"已评价") forState:UIControlStateNormal];
                self.statusBtT.backgroundColor = listModel.isComment?HEXCOLOR(0xFBD62D):HEXCOLOR(0xffffff);
                [ self.statusBtT.layer setBorderColor:listModel.isComment?[UIColor clearColor].CGColor:HEXCOLOR(0xDDDDDD).CGColor];
            }else if(listModel.status == 3){//待发货
                [self.statusBtS setTitle:@"联系客服" forState:UIControlStateNormal];
                [self.statusBtT setTitle:@"申请退款" forState:UIControlStateNormal];
            }else if (listModel.status == 1){//待付款
                [self.statusBtS setTitle:@"取消订单" forState:UIControlStateNormal];
                [self.statusBtT setTitle:@"去付款" forState:UIControlStateNormal];
            }else{
                self.statusBtS.hidden = YES;
                self.statusBtT.hidden = YES;
            }
        }else{//待收货
            [self.statusBtS setTitle:@"查询物流" forState:UIControlStateNormal];
            [self.statusBtT setTitle:@"确认收货" forState:UIControlStateNormal];
        }
    }
}

- (IBAction)orderAction:(UIButton *)sender {
    OrderActionType actionType = 10;
    if ([sender.titleLabel.text isEqualToString:@"评价"]) {
        actionType = OrderActionTypeComment;
    }else if ([sender.titleLabel.text isEqualToString:@"联系客服"]){
        actionType = OrderActionTypeCustomerService;
    }else if ([sender.titleLabel.text isEqualToString:@"取消订单"]){
        actionType = OrderActionTypeCancleOrder;
    }else if ([sender.titleLabel.text isEqualToString:@"申请退款"]){
        actionType = OrderActionTypeReturnMoeny;
        
    }else if ([sender.titleLabel.text isEqualToString:@"去付款"]){
        actionType = OrderActionTypePayOrder;
    }else if ([sender.titleLabel.text isEqualToString:@"确认收货"]){
        actionType = OrderActionTypeConfirmOrder;
    }else if ([sender.titleLabel.text isEqualToString:@"查询物流"]){
        actionType = OrderActionTypeLogsticsProgress;
    }
    if (_delegate && [_delegate respondsToSelector:@selector(dealOrderWithActionType: orderListModel:)]) {
        [_delegate dealOrderWithActionType:actionType orderListModel:self.listModel];
    }
}

- (IBAction)lookMoreAction:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(showAllGood:)]) {
        [_delegate showAllGood:self.listModel];
    }
    
}


@end
